package Lee_code;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Lee_198_2 {
    public int rob(int[] nums) {
        int len = nums.length;
        int[] dp = new int[len+1];

        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        if (len<=2)
            return dp[len-1];

        for (int i=2; i<len; i++){
            dp[i] = Math.max(dp[i]+dp[i-1], dp[i]+dp[i-2]);
        }

        return dp[len];
    }
}
